<template>
  <div>
    <van-submit-bar :price="getSum" button-text="提交订单">
      <van-checkbox v-model="allchecked">全选</van-checkbox>
    </van-submit-bar>
  </div>
</template>

<script>
import Vue from "vue";
import { SubmitBar } from "vant";

import{selectall} from "../../apis/cart"
Vue.use(SubmitBar);
export default {
  name: "Submit",
  props: ["list"],
  data() {
    return {};
  },

  mounted() {},

  methods: {},
  computed: {
    getSum() {
      let newArr = this.list.filter((item) => item.flag);
      return newArr.reduce(
        (sum, item) => (sum += item.originprice * item.num * 100),
        0
      );
    },

    allchecked: {
      get() {
        return this.list.every((item) => item.flag);
       
      },
      set(val) {
        this.list.forEach((item) => (item.flag = val)); 
        selectall({userid:localStorage.getItem("userid"),type:val}).then()
      },
    },
  },
};
</script>

<style scoped>
.van-submit-bar{
    bottom: .65rem;
    opacity: .95;
}
</style>